home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 4_0 / FIX_DESK / SOURCE / HFS.C < prev    next >
C/C++ Source or Header  |  1988-09-07  |  3KB  |  124 lines

  1. #include <MacTypes.h>
  2. #include <FileMgr.h>
  3. #include <HFS.h>
  4.  
  5. #include "fix.h"
  6.  
  7.     /* Local prototypes. */
  8.  
  9. void scan_directory(long dir_id, unsigned char *our_name);
  10. void hfs_comment_processing(CInfoPBPtr pb, int is_dir);
  11. void hfs_bundle_processing(CInfoPBPtr pb, int is_dir);
  12. void hfs_appl_processing(CInfoPBPtr pb, int is_dir);
  13.  
  14.     /* Disk scanning control for an HFS volume. */
  15.  
  16. void hfs_scan_disk()
  17. {
  18.     CInfoPBRec pb;
  19.  
  20.     pb.dirInfo.ioCompletion = NIL;
  21.     pb.dirInfo.ioNamePtr = NIL;                                /* Handle the    */
  22.     pb.dirInfo.ioVRefNum = volume_refnum;                    /* volume's root */
  23.     pb.dirInfo.ioDrDirID = 0;                                /* directory...  */
  24.     pb.dirInfo.ioFDirIndex = 0;
  25.  
  26.     PBGetCatInfo(&pb, 0);
  27.     if (process_comments)
  28.         hfs_comment_processing(&pb,1);
  29.     if (process_bundles)
  30.         hfs_bundle_processing(&pb,1);
  31.     if (process_appls)
  32.         hfs_appl_processing(&pb,1);
  33.  
  34.     scan_directory(0L, NIL);    /* Start scan at root... */
  35. }
  36.  
  37.     /* Scanner for one directory. */
  38.  
  39. static void scan_directory(dir_id, our_name)
  40.     long dir_id;
  41.     unsigned char *our_name;
  42. {
  43.     register int index, done, result;
  44.     int is_us;
  45.     CInfoPBRec pb;
  46.     unsigned char name[NAME_SIZE];
  47.  
  48.     set_processing(our_name);
  49.     is_us = 1;
  50.     pb.dirInfo.ioCompletion = NIL;
  51.     pb.dirInfo.ioNamePtr = name;
  52.     pb.dirInfo.ioVRefNum = volume_refnum;
  53.  
  54.     index = 1; done = 0;
  55.     while (!done) {
  56.         SystemTask();
  57.         pb.dirInfo.ioDrDirID = dir_id;
  58.         pb.dirInfo.ioFDirIndex = index++;
  59.         result = PBGetCatInfo(&pb, 0);
  60.         if ((result != noErr) || (pb.dirInfo.ioResult != noErr))
  61.             done = 1;
  62.         else {
  63.             if (pb.dirInfo.ioFlAttrib & 0x10) {    /* It's a directory... */
  64.                 if (process_comments)
  65.                     hfs_comment_processing(&pb, 1);
  66.                 if (process_bundles)
  67.                     hfs_bundle_processing(&pb, 1);
  68.                 if (process_appls)
  69.                     hfs_appl_processing(&pb, 1);
  70.                 is_us = 0;
  71.                 scan_directory(pb.dirInfo.ioDrDirID,name);
  72.             }
  73.             else {                            /* It's a file... */
  74.                 if (!is_us) {
  75.                     set_processing(our_name);
  76.                     is_us = 1;
  77.                 }
  78.                 if (process_comments)
  79.                     hfs_comment_processing(&pb, 0);
  80.                 if (process_bundles)
  81.                     hfs_bundle_processing(&pb, 0);
  82.                 if (process_appls)
  83.                     hfs_appl_processing(&pb, 0);
  84.             }
  85.         }
  86.     }
  87. }
  88.  
  89.     /* Do comment processing for a file or directory under HFS. */
  90.  
  91. static void hfs_comment_processing(pb, is_dir)
  92.     CInfoPBPtr pb;
  93.     int is_dir;
  94. {
  95.     if (is_dir)
  96.         remove_fcmt(pb->dirInfo.ioDrFndrInfo.frComment);
  97.     else
  98.         remove_fcmt(pb->hFileInfo.ioFlXFndrInfo.fdComment);
  99. }
  100.  
  101.     /* Do bundle processing for a file or directory under HFS. */
  102.  
  103. static void hfs_bundle_processing(pb,is_dir)
  104.     CInfoPBPtr pb;
  105.     int is_dir;
  106. {
  107.     if (!is_dir)
  108.         remove_bndl(pb->hFileInfo.ioFlFndrInfo.fdCreator);
  109. }
  110.  
  111.     /* Do application list processing for a file or dir under HFS. */
  112.  
  113. static void hfs_appl_processing(pb,is_dir)
  114.     register CInfoPBPtr pb;
  115.     int is_dir;
  116. {
  117.     if ((!is_dir) &&
  118.         (pb->hFileInfo.ioFlFndrInfo.fdType == 'APPL') &&
  119.         (pb->hFileInfo.ioFlFndrInfo.fdFlags & fHasBundle))
  120.         add_application(pb->hFileInfo.ioFlFndrInfo.fdCreator,
  121.                         pb->hFileInfo.ioFlParID,
  122.                         pb->hFileInfo.ioNamePtr);
  123. }
  124.